package com.kexio.enterprise.governance.circuitbreaker.result;

import com.kexio.enterprise.governance.circuitbreaker.enums.CircuitBreakerState;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 熔断器执行结果
 * 
 * @param <T> 结果类型
 * @author Kexio
 * @since 1.0.0
 */
public class CircuitBreakerResult<T> {
    private boolean success;
    private T result;
    private Throwable exception;
    private CircuitBreakerState state;
    private boolean fromFallback;
    private long executionTime;
    private String reason;
    private LocalDateTime timestamp;
    private Map<String, Object> metadata;

    public CircuitBreakerResult(boolean success) {
        this.success = success;
        this.timestamp = LocalDateTime.now();
    }

    public CircuitBreakerResult(T result) {
        this.success = true;
        this.result = result;
        this.timestamp = LocalDateTime.now();
    }

    public CircuitBreakerResult(Throwable exception) {
        this.success = false;
        this.exception = exception;
        this.timestamp = LocalDateTime.now();
    }

    // Getters and Setters
    public boolean isSuccess() { return success; }
    public void setSuccess(boolean success) { this.success = success; }
    
    public T getResult() { return result; }
    public void setResult(T result) { this.result = result; }
    
    public Throwable getException() { return exception; }
    public void setException(Throwable exception) { this.exception = exception; }
    
    public CircuitBreakerState getState() { return state; }
    public void setState(CircuitBreakerState state) { this.state = state; }
    
    public boolean isFromFallback() { return fromFallback; }
    public void setFromFallback(boolean fromFallback) { this.fromFallback = fromFallback; }
    
    public long getExecutionTime() { return executionTime; }
    public void setExecutionTime(long executionTime) { this.executionTime = executionTime; }
    
    public String getReason() { return reason; }
    public void setReason(String reason) { this.reason = reason; }
    
    public LocalDateTime getTimestamp() { return timestamp; }
    public void setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; }
    
    public Map<String, Object> getMetadata() { return metadata; }
    public void setMetadata(Map<String, Object> metadata) { this.metadata = metadata; }
}
